<?php
//模型
class CashBalanceModel extends MY_Model {
	function __construct(){
		parent::__construct();
		$this->table = 'cash_balance';
		$this->list = array();
	}
	
	function get_list($arr,$page=1,$size=10){
		$where = ' 1 ';
		
		if(isset($arr['name']) && !empty($arr['name'])){
			//$where .= " AND name like '%{$arr['name']}%'";
		}
		
		
		$res = $this->_where_get_list($where,$page,$size);
		return $res;
	}
	
	function get_info($id){
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where id='{$id}' limit 1";
		$query = $this->db->query($sql);
		$row = $query->row_array();
		return $row;
	}
	
	function get_prev_balance($date_month){
		
		if(isset($this->list[$date_month])){
			return $this->list[$date_month];
		}
		
		//$sql = "select * from ".$this->db->dbprefix.$this->table." where date_month <'{$date_month}' order by date_month desc limit 1";
		$sql = "select * from ".$this->db->dbprefix.$this->table." where date_month <'{$date_month}' and status = 0 order by date_month desc limit 1";
		$query = $this->db->query($sql);
		$row = $query->row_array();
		
		$this->list[$date_month] = $row;
		
		return $row;
	}

	//获取最新一条数据
	function get_last_balance(){
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where status = 0 order by id desc limit 1";
		$query = $this->db->query($sql);
		$row = $query->row_array();
		return $row;
	}
}

